1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.Characters.FirstPerson
6 {
7     
public class TargetHit : MonoBehaviour
8     {
9         
private static int targetScore = 100;
10         
private static int snowballScore = 5;
11         
private AudioSource pickup;
12         
private Rigidbody playerObject;
13
14         
// Use this for initialization
15         
void Start()
16         {
17             pickup = GameObject.Find(
"AudioSourceSnowball").GetComponent<AudioSource>();
18             playerObject = GameObject.Find(
"RigidBodyFPSController").GetComponent<Rigidbody>();
19         }
20
21         
// Update is called once per frame
22         
void Update()
23         {
24             
25         }
26
27         
public static void hitTarget()
28         {
29             
//Debug.Log("Target Hit! Add score!");
30             
int currscore = DataDictionary.getDD().getlevel1Score();
31             
//Debug.Log("currscore= " + currscore);
32             DataDictionary.getDD().setlevel1Score(currscore + targetScore);
33             
//System.Threading.Thread.Sleep(500);
34         }
35
36         
public static void hitSnowball()
37         {
38             
int currscore = DataDictionary.getDD().getlevel1Score();
39             DataDictionary.getDD().setlevel1Score(currscore + snowballScore);
40             
41         }
42
43         
private void OnTriggerEnter(Collider other)
44         {
45
46             
// Level over
47             
if (other.gameObject.name == "FinalTarget")
48             {
49                 
// Add level1score and timeBonus to totalscore
50                 DataDictionary.getDD().setisPlaying(
false);
51                 
int currscore = DataDictionary.getDD().getlevel1Score();
52                 currscore += DataDictionary.getDD().gettimeBonus();
53                 
int tscore = DataDictionary.getDD().gettotalScore();
54                 DataDictionary.getDD().settotalScore(tscore + currscore);
55
56                 playerObject.constraints = RigidbodyConstraints.FreezePosition;
57                 
return;
58             }
59
60             
if (other.gameObject.name.StartsWith("Snowball"))
61             {
62                 hitSnowball();
63                 Destroy(other.gameObject);
64                 pickup.Play();
65                 
return;
66             }
67
68             
if (!DataDictionary.getDD().hitListContains(other.gameObject.name))
69             {
70                 hitTarget();
71                 DataDictionary.getDD().addhitList(other.gameObject.name);
72             }
73             
74         }
75         
76     }
77 }


Gõ tìm kiếm nhanh...